﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using DotNetNinjaLibrary.Utils;
using DotNetNinjaLibrary.Basics;

namespace DotNetNinjaLibrary
{
    public class MapModel
    {
		private IList<Unit> units;

		public IList<Unit> Units { get { return this.units; } }
		public int Width { get; private set; }
		public int Height { get; private set; }

		public MapModel(int width, int height)
			:this(width, height, new List<Unit>())
		{
		}

		public MapModel(int width, int height, IList<Unit> units)
        {
			this.units = units;
			this.Width = width;
			this.Height = height;
        }

		public void AddUnit(Unit unit)
		{
			this.units.Add(unit);
		}

		public void RemoveUnit(Unit unit)
		{
			this.units.Remove(unit);
		}

		public bool IsMovePossible(Point destination, Size unitSize)
		{
			// TODO: Add state for the squares availability. Looping through all units is not fastest aproach for this.
			return destination.X >= 0 && destination.Y >= 0 &&
				destination.X < this.Width - unitSize.Height && destination.Y < this.Height - unitSize.Height
				&& this.Units.All(u => !IntersectionHelper.IntersectsWith(destination, unitSize, u.Location, u.Size));
		}

		public void MoveUnit(Unit unit, Point destination)
		{
			
		}
	}
}